/*
 * time.c
 *
 *  Created on: Dec 15, 2008
 *      Author: michael
 */

#include <comlib.h>

TIMESTRU GetTime()
{
	TIMESTRU timestru;

	time_t time1;
	struct tm * when;

	time(&time1);
	when = localtime(&time1);

	timestru.nY = when->tm_year + 1900;
	timestru.nM = when->tm_mon + 1;
	timestru.nD = when->tm_mday;

	timestru.nH = when->tm_hour;
	timestru.nMin = when->tm_min;
	timestru.nS = when->tm_sec;

	return timestru;
}

TIMESTRU GetOffsetTime(TIMESTRU timestru, int nOffsetSec)
{
	TIMESTRU timestruAfter;
	time_t ttime;
	struct tm when;

	memset(&when, 0, sizeof(when));
	when.tm_year = timestru.nY - 1900;
	when.tm_mon = timestru.nM - 1;
	when.tm_mday = timestru.nD;
	when.tm_hour = timestru.nH;
	when.tm_min = timestru.nMin;
	when.tm_sec = timestru.nS;

	ttime = mktime(&when) + nOffsetSec;

	when = *localtime(&ttime);

	timestruAfter.nY = when.tm_year + 1900;
	timestruAfter.nM = when.tm_mon + 1;
	timestruAfter.nD = when.tm_mday;
	timestruAfter.nH = when.tm_hour;
	timestruAfter.nMin = when.tm_min;
	timestruAfter.nS = when.tm_sec;

	return timestruAfter;
}
